@ECHO OFF
for /f "delims=" %%b in ("%cd%") do set fold=%%~nb

SET PLUGIN_NAME=%fold%
SET SCRIPTING_FOLDER=..\..\..\scripting_base
SET FOLDERS_FILE=mod_folders.txt
SET PLUGIN_FILE_NAME=%PLUGIN_NAME%.sp
SET BUILD_FOLDER=%CD%\build
SET SOURCES_FOLDER=%BUILD_FOLDER%\addons\sourcemod\scripting
SET PLUGINS_FOLDER=%BUILD_FOLDER%\addons\sourcemod\plugins

SET COMPILER_NAME=spcomp.exe
SET COMPILED_PLUGIN_NAME=%PLUGIN_NAME%.smx

XCOPY "%SOURCES_FOLDER%\include" "%SCRIPTING_FOLDER%\include" /D /E /C /R /I /K /Y 
IF ERRORLEVEL 1 ECHO !!!ERROR COPY INCLUDE FOLDER!!!
%SCRIPTING_FOLDER%\%COMPILER_NAME% "%SOURCES_FOLDER%\%PLUGIN_FILE_NAME%"

@ECHO.

DEL /S /Q %PLUGINS_FOLDER%\*.* > NUL
MOVE %COMPILED_PLUGIN_NAME% %PLUGINS_FOLDER% > NUL

FOR /F "tokens=*" %%i IN (%FOLDERS_FILE%) DO (
	ECHO Copying to %%i
	XCOPY "%BUILD_FOLDER%" "%%i" /D /E /C /R /I /K /Y > NUL
	IF ERRORLEVEL 1 ECHO !!!ERROR COPY BUILD IN %%i
)

PAUSE